var ApacheAssistant = Class.create(AbstractModule, {

setupWidgets: function() {

		//About
		this.controller.setupWidget(Mojo.Menu.appMenu, {
			omitDefaultItems: true
		}, {
			visible: true,
			items: [
      		Mojo.Menu.editItem,
			{ label: "Disclaimer", command: "do-disclaimer" },					
				{ label: "License", command: "do-license" },
				{ label: "Help", command: "do-help" }
			]
		});

this.help = true;

	  this.toggleModel = {
			arfCHK: false
		};


	this.toggleunit =
	{
		modelProperty: 'togglestate',
		trueLabel: 'FiO2&ge;0.5',
	falseLabel: 'FiO2<0.5'
	};
	this.togglemodel = {
		togglestate: true
	};
	this.controller.setupWidget("fio2Field", this.toggleunit, this.togglemodel);
	this.controller.listen("fio2Field", Mojo.Event.propertyChanged, this.unitChanged.bindAsEventListener(this));


		this.controller.setupWidget("immuno", {
			label: "<span class=\"si\">Immuno<sup>*</sup>)</span>",
			choices: [
				{ label: "No", value: 0},
				{ label: "Yes, no operation", value: 5},
				{ label: "Yes, elective op", value: 2},
				{ label: "Yes, emergency op", value: 5}
				
			]
		}, this.immunoModel = {
			value: 0
		});
	
		this.controller.setupWidget("arfCHK", {
			modelProperty: "arfCHK"
		}, this.toggleModel);
	
	
	this.controller.setupWidget("ageField", {
		charsAllow: isValidNumber,
		modifierState: Mojo.Widget.numLock
	}, 
	{value: age});
	
	this.controller.setupWidget("temperatureField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, 
	{});


		this.controller.setupWidget("pHField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, 
	{});

		this.controller.setupWidget("hrField", {
		charsAllow: isValidNumber,
		modifierState: Mojo.Widget.numLock
	}, 
	{});

		this.controller.setupWidget("rrField", {
		charsAllow: isValidNumber,
		modifierState: Mojo.Widget.numLock
	}, 
	{});

		this.controller.setupWidget("sodiumField", {
		charsAllow: isValidNumber,
		modifierState: Mojo.Widget.numLock
	}, 
	{});
	
		this.controller.setupWidget("potassiumField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, 
	{});

		this.controller.setupWidget("creatinineField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, 
	{value: creatinine});

		this.controller.setupWidget("hematocritField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, 
	{value: "40"});

		this.controller.setupWidget("wbcField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, 
	{});
	
	
	this.controller.setupWidget("gcsField", {
		charsAllow: isValidNumber,
		modifierState: Mojo.Widget.numLock
	}, 
	{value: gcs});

	this.controller.setupWidget("o2Field", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, 
	{value: aagrad});

	
},

unitChanged: function() {
//change unit display in bmi scene
var unitchoice = this.togglemodel.togglestate;

if (!unitchoice){
$("o2Unit").update("<span class=\"si\">PaO2 mmHg</span>");
}

if (unitchoice){
$("o2Unit").update("<span class=\"si\">A-a gradient</span>");
}
},


	calculate: function() {
	var result = apachecalc(parseInt(this.immunoModel.value),this.toggleModel.arfCHK,$("ageField").mojo.getValue(),$("temperatureField").mojo.getValue(),$("pHField").mojo.getValue(),$("hrField").mojo.getValue(),$("rrField").mojo.getValue(),$("sodiumField").mojo.getValue(),$("potassiumField").mojo.getValue(),$("creatinineField").mojo.getValue(),$("hematocritField").mojo.getValue(),$("wbcField").mojo.getValue(), $("gcsField").mojo.getValue(),this.togglemodel.togglestate, $("o2Field").mojo.getValue());
	age=result.age;
	return "The score is " + result.value +"<br />The estimated mortality is "+ result.mort +"%";
	}
});





